package gui.viewLattice;

import java.awt.BorderLayout;
import java.io.File;
import java.util.concurrent.ExecutionException;

import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.SwingWorker;

import svg.SVGViewer;

import framework.classification.entities.ClAbstractEntity;
import framework.classification.library.IOCLassificationDirectory;


	

public class ViewLattice extends JPanel {

	private ClAbstractEntity cl;
	
	public ViewLattice(ClAbstractEntity cl){
		setLayout(new BorderLayout());
		final File f = new File(cl.getPathSVGLattice());
		if (!f.exists()) cl.getAbstractClassfication().generateClEntityImage(cl,"",IOCLassificationDirectory.SVG);
		
		while(!f.exists()){}
		
		
		SwingWorker<SVGViewer, Void> work = new SwingWorker<SVGViewer, Void>(){
			protected SVGViewer doInBackground() throws Exception {
				return new SVGViewer("file:"+f.getAbsolutePath());
			}
			protected void done(){
				try {
					add(get());
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ExecutionException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
		work.execute();
		
		//add(new SVGViewer("file:"+cl.getPathSVGLattice()));
	}
	
	
	
	
	
	
	public ClAbstractEntity getClassification(){return cl;}
}
